//
//  Person.m
//  OC05_homework
//
//  Created by Hanlingyu on 16/7/8.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "Person.h"

@implementation Person

- (instancetype)initWithName:(NSString *)name sex:(NSString *)sex age:(NSInteger)age {
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
        _sex = sex;
    }
    return self;
}
- (NSString *)description {

    return [NSString stringWithFormat:@"name:%@, sex: %@, age: %ld", _name, _sex, _age];

}
- (NSComparisonResult)compareByAge:(Person*)per{
    //self拿到当前对象，per拿到另外一个对象
    //两个对象比较年龄
    if(self.age < per.age){
        return NSOrderedAscending;//-1
    }else if(self.age == per.age){
        return NSOrderedSame;//0
    }else{
        return NSOrderedDescending;//1
    }
}
- (NSComparisonResult)compareByName:(Person *)per {

    return [self.name compare:per.name];
}

- (NSComparisonResult)compareBySex:(Person *)per {
    
    return [self.sex compare:per.sex];
}



//- (NSComparisonResult)comparePersonAge:(Person *)person{
//    NSComparisonResult result = [[NSNumber numberWithInteger:person.age] compare:[NSNumber numberWithInteger:self.age]];//注意:基本数据类型要进行数据转换
//    return result;
//}
@end
